import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import ying.model.Student;

import java.io.InputStream;
import java.util.List;

/**
 * ClassName: MybatisDemo01
 * Package: PACKAGE_NAME
 * Description:
 *
 * @Author 刘英杰
 * @Create 2024/10/31 19:27
 * @Version 1.0
 */
public class MybatisDemo01 {
    @Test
    public void testFindBySno() {
        //1.构建一个输入流,读取sqlMapConfig.xml文件
        InputStream is = MybatisDemo01.class.getClassLoader().getResourceAsStream("sqlMapConfig.xml");
        //2.构建一个sqlSessionFactory工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        //3.通过sqlSessionFactory工厂获取一个sqlSession会话接口
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //4.调用sqlSession方法进行CRUD操作,第一个参数传入statement id值
        Student student = sqlSession.selectOne("test.findBySno",201215122);
        System.out.println(student);
        //5.关闭会话
        sqlSession.close();
    }
    @Test
    public void testFindBySname() {
        InputStream is = MybatisDemo01.class.getClassLoader().getResourceAsStream("sqlMapConfig.xml");

        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);

        SqlSession sqlSession = sqlSessionFactory.openSession();

//        sqlSession.selectList("test.findBySname", "%张%").forEach(System.out::println);
        sqlSession.selectList("test.findBySname","张").forEach(System.out::println);

        sqlSession.close();
    }
}
